package com.attendance.service.impl;

import com.attendance.common.CommonPage;
import com.attendance.common.CommonResult;
import com.attendance.mapper.PersonalScoreMapper;
import com.attendance.pojo.Pages;
import com.attendance.pojo.PersonalScore;
import com.attendance.service.PersonalScoreService;
import com.attendance.vo.PersonalScoreVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonalScoreServiceImpl implements PersonalScoreService {

    @Autowired
    private PersonalScoreMapper personalScoreMapper;

    @Override
    public CommonResult selectAll(Pages pages) {
        PageHelper.startPage(pages.getPage(),pages.getNum());
        List<PersonalScoreVo> list = personalScoreMapper.selectAll();
        if(list.size()==0){
            return CommonResult.failed("没有相关数据");
        }
        return CommonResult.success(CommonPage.restPage(list),"查询成功");
    }

    @Override
    public CommonResult selectByName(PersonalScoreVo personalScoreVo,Pages pages) {
        PageHelper.startPage(pages.getPage(),pages.getNum());
        List<PersonalScoreVo> list = personalScoreMapper.selectByName(personalScoreVo.getStuName(), personalScoreVo.getCouName());
        if(list.size()==0){
            return CommonResult.failed("没有相关数据");
        }
        CommonPage<PersonalScoreVo> pageInfo = CommonPage.restPage(list);
        return CommonResult.success(pageInfo,"查询成功");
    }

    @Override
    public CommonResult selectById(int psId) {
        PersonalScoreVo personalScoreVo = personalScoreMapper.selectById(psId);
        if(personalScoreVo != null){
            return CommonResult.success(personalScoreVo,"查询详情成功");
        } else {
            return CommonResult.failed("查询详情失败");
        }
    }

    @Override
    public CommonResult addPersonalScore(PersonalScore personalScore) {
        int i = personalScoreMapper.addPersonalScore(personalScore);
        if(i ==1){
            return CommonResult.success("新增成功");
        }else {
            return CommonResult.failed("新增失败");
        }
    }

    @Override
    public CommonResult updatePersonalScore(PersonalScore personalScore) {
        int i = personalScoreMapper.updatePersonalScore(personalScore);
        if(i ==1){
            return CommonResult.success("修改成功");
        }else {
            return CommonResult.failed("修改失败");
        }
    }

    @Override
    public CommonResult modifyPersonalScore(String psId) {
        int i = personalScoreMapper.modifyPersonalScore(psId);
        if(i ==1){
            return CommonResult.success("修改成功");
        }else {
            return CommonResult.failed("修改失败");
        }
    }
}
